import { request } from "../../request/request.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
import { showToast } from "../../utils/asyncWx.js";
var app = getApp()
// pages/login/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName:"",
    password:"",
    checkNum:""
  },
  async submitUserInfo(){
    const _this = this
    const userName = this.data.userName;
    const password = this.data.password;
    const checkNum = this.data.checkNum;
    console.log(this.data);
    if(userName ==""){
      wx.showModal({
        title: '手机号不允许为空'
      })
      return;
    }
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(userName)) {
      wx.showModal({
        title: '手机号格式不正确'
      })
      return;
    }
    if (password == "") {
      wx.showModal({
        title: '密码不允许为空'
      })
      return;
    }
    if ( password.length  < 6 || password.length  > 20 ) {
      wx.showModal({
        title: '密码长度位6-20位'
      })
      return;
    }
    if (checkNum == "") {
      wx.showModal({
        title: '验证码不允许为空'
      })
      return;
    }
    const res=await request({url:"/login",data:{"userName": userName,"passWord": password}});
    console.log( res);
    if (res.code == '10000'){
      wx.redirectTo({
        url: '/pages/index/index',
      })
    }else{
      _this.setData({ userName:"", password:"", checkNum:""})
      wx.showModal({
        title: res.msg
      })
      
     
    }
  },
  updateValue: function(e) {
    this.setData(app.updateValue(e))
  },
  userInfoHandler(e){
    console.log(e); 
     wx.showModal({
       title: "获取用户名称:"+e.detail.userInfo.nickName
     })
  

  }
  
  
})